<template>
  <div class="person-Demo">
    <div class="pic-name">
      <div class="pic">
        <router-link
          :to="{
            name: targetRoute,
            query: {
              id: personData.data.userId,
            },
          }"
          target="_blank"
        >
          <img
            src="@/assets/szptImages/images/builderHeader.png"
            alt=""
            srcset=""
            v-if="!avatarShow"
          />
          <img
            :src="personData.data.avatar"
            alt=""
            srcset=""
            v-if="avatarShow"
          />
        </router-link>
      </div>

      <div class="name-remark">
        <router-link
          :to="{
            name: targetRoute,
            query: {
              id: personData.data.userId,
            },
          }"
          target="_blank"
        >
          <div class="name">
            <router-link to="#">
              {{ personData.data.userName }}
            </router-link>
          </div>
          <div class="remark">
            <span>{{
              personData.data.remark
                ? personData.data.remark
                : "系统签名送个每个小可爱~"
            }}</span>
          </div>
        </router-link>
      </div>
    </div>
    <div class="focus">
      <div class="concern" v-if="loadUserID == postUserID ? false : true">
        <div
          @click="changeFocusFlag(personData.data.userId)"
          class="concern-btn"
          v-show="!focusFlag"
        >
          关注
        </div>
        <div
          @click="changeFocusFlag(personData.data.userId)"
          class="cancel-concern-btn"
          v-show="focusFlag"
        >
          已关注
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { parse_collect_concern } from "@/api/szpt/parse";
export default {
  data() {
    return {
      loadUserID: true,
      postUserID: false,
      focusFlag: false,
      // 头像展示
      avatarShow: true,
      // 目标路由
      targetRoute: "szptPersonalCenter",
    };
  },
  props: {
    personData: {
      require: true,
    },
  },
  methods: {
    // 改变关注状态
    changeFocusFlag(userId) {
      parse_collect_concern(userId, "SZPT_SYSUSER_SYSUSER_FOCUS")
        .then((resp) => {
          if (resp.code === 200) {
            if (this.focusFlag) {
              this.$message.success("已取消关注");
            } else {
              this.$message.success("关注成功!");
            }
            this.focusFlag = !this.focusFlag;
          } else {
            this.$message.error("状态更改失败!");
          }
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
    initPersonDemo() {
      const demoPeron = this.$props.personData;
      if (demoPeron.data.avatar) {
        // 判断头像状态
        this.avatarShow = true;
      } else {
        this.avatarShow = false;
      }
      this.focusFlag = this.$props.personData.actionFlagDTO.focusFlag;
    },
  },
  mounted() {
    this.initPersonDemo();
  },
};
</script>

<style lang="scss" scoped>
.person-Demo {
  width: 100%;
  height: 90px;
  padding: 10px 30px 10px 30px;
  border-bottom: 1px solid #ececec;
  display: flex;
  .pic-name {
    width: 80%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    .pic {
      width: 70px;
      height: 70px;
      border-radius: 35px;
      overflow: hidden;
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }
    .name-remark {
      width: 85%;
      height: 100%;
      margin-left: 10px;
      .name {
        width: 100%;
        height: 50%;
        font-weight: bold;
        line-height: 35px;
      }
      .name:hover {
        color: rgb(0, 195, 255);
      }
      .remark {
        width: 100%;
        height: 50%;
        font-size: 14px;
        color: #999;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }
  }
  .focus {
    width: 20%;
    height: 100%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    .concern-btn {
      height: 80%;
      width: 80px;
      color: white;
      text-align: center;
      line-height: 28px;
      border-radius: 10px;
      cursor: pointer;
      background-color: rgb(0, 195, 255);
    }
    .cancel-concern-btn {
      height: 80%;
      width: 80px;
      color: #999;
      text-align: center;
      line-height: 28px;
      border-radius: 10px;
      cursor: pointer;
      background-color: rgb(233, 233, 233);
    }
    .concern-btn:hover {
      background-color: rgb(85, 213, 252);
    }
  }
}
.person-Demo:hover {
  background-color: #f5f5f5;
}
</style>
